package com.ezops.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.ezops.dao.generics.dao.hibernate.GenericDAOImpl;
import com.ezops.models.Report;

@Repository
public class ReportDAOImpl extends GenericDAOImpl<Report, Serializable> implements
		ReportDAO {

	public List<Report> getReportListSeq() {
		Query query =getSession()
				.createSQLQuery(
						"SELECT R.REPORT_ID,R.FILE_NAME,R.REPORT_CATEGORY,R.FILE_LOCATION,R.GROUP_ID,R.FILE_DATA,R.AS_OF_DATE FROM REPORT R , USER_PREFERENCE UP WHERE R.REPORT_CATEGORY= UP.CATEGORY  AND UP.CREATED_ON = ( SELECT max(CREATED_ON) FROM USER_PREFERENCE IUP WHERE IUP.USER_ID = 'demo' AND IUP.RESOURCE_NAME= 'Dashboard' AND IUP.CATEGORY = R.REPORT_CATEGORY ) AND R.GROUP_ID = ( SELECT U.GROUP_ID FROM EZOPS_USER U WHERE U.USER_ID='demo' ) AND R.AS_OF_DATE = ( SELECT max(IR.AS_OF_DATE) FROM REPORT IR WHERE  IR.REPORT_CATEGORY= R.REPORT_CATEGORY) ORDER BY UP.SEQUENCE_NBR")
				.addEntity(Report.class);
		System.out.println(">>>>>>>>>>>>>>>>>" + query);
		// query.setParameter("resourceName", "Dashboard");
		// query.setParameter("userId", userId);
		List<Report> reportListSeq = query.list();
		return reportListSeq;
	}
}
